﻿@{
    ViewBag.Title = "SendForm";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var TypeId = request('TypeId');
    $(function () {      
        GetObject();
    });

    function GetObject() {
        $("#CanPerform").html("");
        $("#Perform").html("");
        $.ajax({
            url: "/DailyEventManage/OpenShop/GetTypeRoleUser?TypeId=" + TypeId,
            type: "GET",
            dataType: "json",
            async: false,
            success: function (data) {
                var _Perform = "";
                $.each(data, function (i, item) {
                    _Perform += "<option value='" + item.Id + "' >" + item.Name + "</option>";
                });
                $("#CanPerform").append(_Perform);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                dialogMsg(errorThrown, -1);
            }
        });
        $("#CanPerform option").dblclick(function () {
            $(this).attr("hidden", "hidden");
            $("#Perform").append("<option value='" + $(this).attr("value") + "' >" + $(this).text() + "</option>")
            $("#Perform option").dblclick(function () {
                $("#CanPerform option[value=" + $(this).attr("value") + "]").removeAttr("hidden");
                $(this).remove();
            })
        });
    }

    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        if ($("#PerformNumber").val()<1) {
            dialogMsg("执行人数最少为1人", 0);
            return;
        }
        var Perform = $("#Perform option");
        if (Perform.length < $("#PerformNumber").val()) {
            dialogMsg("选择的可执行人数最少为" + $("#PerformNumber").val() + "人。", 0);
            return;
        }
        if (Perform.length > 0) {
            top.frames["Form"].$("#Perform").html("");
            top.frames["Form"].$("#Send").val("");
            var Value = "";
            Perform.each(function () {
                top.frames["Form"].$("#Perform").append("<option value='" + $(this).attr("value") + "' >" + $(this).text() + "</option>");
                if (Value != "") Value += ",";
                Value += $(this).text();
            });
            Value += "其中" + $("#PerformNumber").val() + "个人执行";
            top.frames["Form"].$("#Send").attr('title', $("#PerformNumber").val());
            top.frames["Form"].$("#Send").val(Value);
            top.frames["Form"].$("#SendTable").removeAttr("hidden");
            top.frames["Form"].$("#State").val("派单中（已派单）");
        }
        dialogMsg("操作成功。", 1);
        dialogClose();
    }
</script>
<div style="margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr style="display:none;">
            <th class="formTitle">执行人数</th>
            <td class="formValue">
                <input id="PerformNumber" readonly type="number" class="form-control" min="1" max="1" value="1" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">可执行人</th>
            <td class="formValue"></td>
        </tr>
    </table>
    <div style="margin-left:30px;margin-top:10px;">
        <select multiple class="form-control" id="CanPerform" style="height:180px;width:150px;margin-right:30px;float:left;"></select>
        <select multiple class="form-control" id="Perform" style="height: 180px; width: 150px; float: left;"></select>
    </div>
</div>
